package com.noah.note.model;

import com.noah.note.global.BaseModel;
import com.noah.note.global.Const;
import com.noah.note.global.OkHttpCallback;
import com.noah.note.manager.HttpManager;
import com.noah.note.utils.AppUtils;
import com.noah.note.utils.LogUtils;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Callback;

/**
 * Created by zzh on 2018/5/15.
 */

public class LoginModel extends BaseModel {
    public void login(String username, String password, OkHttpCallback okHttpCallback) {
        AppUtils.getFlow("登录");
        //LogUtils.i("登录是主线程:" + (Looper.myLooper() == Looper.getMainLooper()));
        //url += "username=" + username + "&password=" + password;
        Map<String, String> map = new HashMap<>();
        map.put("username", username);
        map.put("password", password);
        HttpManager.getInstance().post(Const.API_LOGIN, map, okHttpCallback,false);
    }

    public void login(String token, OkHttpCallback okHttpCallback) {
        AppUtils.getFlow("登录");
        //LogUtils.i("登录是主线程:" + (Looper.myLooper() == Looper.getMainLooper()));
        //url += "username=" + username + "&password=" + password;
        Map<String, String> map = new HashMap<>();
        map.put("token", token);
        HttpManager.getInstance().post(Const.API_LOGIN, map, okHttpCallback,false);
    }

    public void register(String username, String password, String name, OkHttpCallback okHttpCallback) {
        //url += "username=" + username + "&password=" + password;
        Map<String, String> map = new HashMap<>();
        map.put("username", username);
        map.put("password", password);
        map.put("name", name);
        HttpManager.getInstance().post(Const.API_REGISTER, map, okHttpCallback,false);
    }

    public void getCommentList(long nid, long time, OkHttpCallback okHttpCallback) {
        AppUtils.getFlow("登录");
        //LogUtils.i("登录是主线程:" + (Looper.myLooper() == Looper.getMainLooper()));
        HttpManager.getInstance().get(Const.API_GET_COMMENT_LIST, okHttpCallback);
    }

}
